import fs from 'fs';
import path from 'path';

const BASE_DIE = __dirname;
const SOURCES_DIR = path.join(BASE_DIE,'src');
const DIST_DIR = path.join(BASE_DIE,'dist');
const packageJson = path.join(BASE_DIE,'package.json');

const packageJsonDist = path.join(DIST_DIR,'package.json');

const readMe = path.join(BASE_DIE,'readme.md');
const readMeDIST = path.join(DIST_DIR,'readme.md');

const readMeCN = path.join(BASE_DIE,'readme_CN.md');
const readMeCNDIST = path.join(DIST_DIR,'readme_CN.md');

function readJson(filePath) {
  return JSON.parse(fs.readFileSync(filePath))
}

const copyReadme = ()=>{
    fs.copyFileSync(readMe, readMeDIST)
}

const modifyPackageJson = (keyValues) => {
    let _ = readJson(packageJson);
    keyValues.forEach(element => {
        let key = element.key;
        let value = element.value;
        _[key] = value;
    });
    fs.writeFileSync(packageJsonDist,JSON.stringify(_,null,2))
}


copyReadme()
modifyPackageJson([
    {key:"main", value:"index.ts"}
])

